package public

import (
	"dc-go/global"
	"dc-go/model"
	"runtime"

	"github.com/gin-gonic/gin"
)

type ApiDb struct{}

func (a *ApiDb) CheckDb(c *gin.Context) {
	goVersion := runtime.Version()
	ginVersion := gin.Version

	if global.DcDb != nil {
		global.DcLogger.Info("数据库连接正常")
		model.ResponseSuccessMessageData(gin.H{
			"go_version":  goVersion,
			"gin_version": ginVersion,
		}, "数据库连接正常", c)
		return
	} else {
		model.ResponseErrorMessage("数据库炸了", c)
		global.DcLogger.Fatal("数据库炸了")
		return
	}
}

func (a *ApiDb) InitDb(c *gin.Context) {
	err := servicePublic.ServiceDb.InitDb()
	if err != nil {
		model.ResponseErrorMessage(err.Error(), c)
	} else {
		model.ResponseSuccessMessage("初始化数据成功", c)
	}
}
